package extend02;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2022-11-15
 * Time: 23:14
 */
class per{
    String name;
    int age;

    public per(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println(name+"吃饭");
    }
}
class stu extends per{
    public stu(String name, int age) {
        super(name, age);
    }
    @Override
    public void eat(){
        System.out.println(name+"吃学生餐");
    }
}
class tea extends per{
    public tea(String name, int age) {
        super(name, age);
    }
    @Override
    public void eat(){
        System.out.println(name+"吃教师餐");
    }
}
public class test8 {
    // 编译器在编译代码时，并不知道要调用Dog 还是 Cat 中eat的方法
    // 等程序运行起来后，形参a引用的具体对象确定后，才知道调用那个方法
    // 注意：此处的形参类型必须时父类类型才可以
    public static void test(per a) {
        a.eat();
    }
    public static void main(String[] args) {
        stu stu1 = new stu("张三",99);
        tea tea1 = new tea("韩顺平",44);
        test(stu1);
        test(tea1);
    }
}